package com.dingwei.lesyndrome.ui.activity;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.allen.library.SuperButton;
import com.allen.library.SuperTextView;
import com.dingwei.lesyndrome.R;
import com.dingwei.lesyndrome.mvp.view.Contract;
import com.dingwei.lesyndrome.utils.DialogUtil;
import com.lihao.baselibrary.base.BaseActivity;
import com.lihao.baselibrary.utils.AppManager;
import com.lihao.baselibrary.utils.DataCleanManager;
import com.lihao.baselibrary.weight.TitleBar;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created time 2018/2/28.
 * Creator 南柯一梦丶 on
 * Personal signature 余生还长 何必慌张
 * Page description : 设置
 */

public class SetupActivity extends BaseActivity implements Contract.SetupView {
    @Bind(R.id.title_bar)
    TitleBar titleBar;
    @Bind(R.id.about_us)
    SuperTextView aboutUs;
    @Bind(R.id.feedback)
    SuperTextView feedback;
    @Bind(R.id.clear)
    SuperTextView clear;
    @Bind(R.id.btn_exit)
    SuperButton btnExit;

    @Override
    protected int getContentViewId() {
        return R.layout.activity_setup;
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initView() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @OnClick({R.id.about_us, R.id.feedback, R.id.clear, R.id.btn_exit})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.about_us:
                intent = new Intent(BaseActivity.context, AboutUsActivity.class);
                startActivity(intent);
                break;
            case R.id.feedback:
                intent = new Intent(BaseActivity.context, FeedbackActivity.class);
                startActivity(intent);
                break;
            case R.id.clear:
                DialogUtil.showAlertDialogChoose(BaseActivity.context, "温馨提醒", "是否确认清除" + clear.getRightString() + "缓存", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        switch (which) {
                            case DialogUtil.BUTTON1:
                                dialog.dismiss();
                                break;
                            case DialogUtil.BUTTON2:
                                dialog.dismiss();
                                DataCleanManager.clearAllCache(BaseActivity.context);
                                clear.setRightString("0.0K").useShape();
                                showToast("清理缓存成功");
                                break;
                        }
                    }
                });
                break;
            case R.id.btn_exit:
                BaseActivity.value.setIsLogin(false);
                BaseActivity.value.setToken("");
                BaseActivity.value.setHeadImg("");
                BaseActivity.value.setUserName("");
                BaseActivity.value.setPhone("");
                intent = new Intent(BaseActivity.context,MainActivity.class);
                startActivity(intent);
                AppManager.getAppManager().finishActivity(PersonalCenterActivity.class);
                AppManager.getAppManager().finishActivity();
                break;
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        try {
            clear.setRightString(DataCleanManager.getTotalCacheSize(BaseActivity.context)).useShape();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
